﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _89二维数组顺时针旋转90度
{
    internal class Array2DRotateHelper
    {
        private int[,] newArray;
        public int[,] array;

        public Array2DRotateHelper(int[,] array)
        {
            //把给我的数组存起来
            this.array = array;
            //创建一个新数组
            newArray = new int[array.GetLength(1), array.GetLength(0)];
        }

        /// <summary>
        /// 需要取返回值
        /// </summary>
        /// <returns></returns>
        public int[,] Rotate()
        {
            int c1 = newArray.GetLength(1) - 1;//新数组最大列
            for (int r = 0; r < array.GetLength(0); r++)
            {
                int r1 = 0;//新数组的行从0开始
                for (int c = 0; c < array.GetLength(1); c++)
                {
                    newArray[r1, c1] = array[r, c];
                    r1++;
                }
                c1--;
            }
            int[,] temp = array;
            array = newArray;
            newArray = temp;
            return array;
        }

        public int[,] Rotate(int times)
        {
            for (int i = 0; i < times; i++)
            {
                Rotate();
            }
            return array;
        }
    }
}